import requests


# 封装 类 - 接口对象层
class EmpManageApi(object):
    # 添加员工
    def add_emp(self, req_head, req_data):
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user/",
                             headers=req_head, json=req_data)
        return resp

    # 查询员工
    def query_emp(self, emp_id, req_head):
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id, headers=req_head)
        return resp

    # 修改员工
    def modify_emp(self, emp_id, req_head, req_data):
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                            headers=req_head, json=req_data)
        return resp

    # 删除员工
    def del_emp(self, emp_id, req_head):
        return requests.delete(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id, headers=req_head)


# 自测
if __name__ == '__main__':
    emp = EmpManageApi()

    # 准备请求头
    req_head = {"Authorization": "675c1d26-8e74-4dd6-a253-089b08c65718"}

    # 准备请求体
    req_body = {
        "username": "jack123",
        "mobile": "13858043400",
        "workNumber": "666"
    }
    # resp = emp.add_emp(req_head, req_body)
    # print("添加员工：", resp.json())

    # 准备 员工id
    emp_id = "1570674425399881728"
    # 准备 请求体
    modify_req_body = {"username": "小猪佩奇"}

    resp = emp.modify_emp(emp_id, req_head, modify_req_body)
    print(resp.json())
